package com.ruoyi.pms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.pms.domain.vo.TaskDeferVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pms.domain.TaskDefer;
import com.ruoyi.pms.service.ITaskDeferService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务延期Controller
 * 
 * @author ruoyi
 * @date 2024-12-09
 */
@RestController
@RequestMapping("/pms/task/defer")
public class TaskDeferController extends BaseController
{
    @Autowired
    private ITaskDeferService pmsProjectTaskDeferService;

    /**
     * 查询任务延期列表
     */
    @GetMapping("/page")
    public TableDataInfo page(TaskDefer taskDefer)
    {
        startPage();
        List<TaskDefer> list = pmsProjectTaskDeferService.selectPmsProjectTaskDeferList(taskDefer);
        return getDataTable(list);
    }

    /**
     * 查询任务延期审核
     */
    @GetMapping("/pageAudit")
    public TableDataInfo pageAudit(TaskDefer taskDefer)
    {
        startPage();
        List<TaskDeferVO> list = pmsProjectTaskDeferService.selectAuditDeferList(taskDefer);
        return getDataTable(list);
    }

    /**
     * 查询任务延期列表
     */
    @GetMapping("/list")
    public AjaxResult list(TaskDefer taskDefer)
    {
        List<TaskDefer> list = pmsProjectTaskDeferService.selectPmsProjectTaskDeferList(taskDefer);
        return success(list);
    }

    @GetMapping("/auditDefer")
    public AjaxResult auditDefer(TaskDefer taskDefer)
    {
        pmsProjectTaskDeferService.auditDefer(taskDefer);
        return success(1);
    }


    /**
     * 导出任务延期列表
     */
    @Log(title = "任务延期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskDefer taskDefer)
    {
        List<TaskDefer> list = pmsProjectTaskDeferService.selectPmsProjectTaskDeferList(taskDefer);
        ExcelUtil<TaskDefer> util = new ExcelUtil<TaskDefer>(TaskDefer.class);
        util.exportExcel(response, list, "任务延期数据");
    }

    /**
     * 获取任务延期详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(pmsProjectTaskDeferService.selectPmsProjectTaskDeferById(id));
    }

    /**
     * 新增任务延期
     */
    @Log(title = "任务延期", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody TaskDefer taskDefer)
    {
        return toAjax(pmsProjectTaskDeferService.insertPmsProjectTaskDefer(taskDefer));
    }

    /**
     * 修改任务延期
     */
    @Log(title = "任务延期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskDefer taskDefer)
    {
        return toAjax(pmsProjectTaskDeferService.updatePmsProjectTaskDefer(taskDefer));
    }

    /**
     * 删除任务延期
     */
    @Log(title = "任务延期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(pmsProjectTaskDeferService.deletePmsProjectTaskDeferByIds(ids));
    }

    /**
     * 删除任务延期
     */
    @Log(title = "任务延期", businessType = BusinessType.DELETE)
    @GetMapping("/deleteDeferTask")
    public AjaxResult deleteTask(TaskDefer taskDefer)
    {
        return toAjax(pmsProjectTaskDeferService.deletePmsProjectTaskDeferById(taskDefer.getId()));
    }
}
